<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/layer/layer.js"></script>
    <SCRIPT language=javascript src="../../static/layer/layer.js"></SCRIPT>
</head>
<style>
    #test1{
        display: inline-block;
        width:15%;
    }
#box .content table td button a{
            font-size: .6rem
    }
</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}

<div id="box" class="fl">
    <div class="content" style="height: 100%">
        <h3 style="color:  #3D89CB">会员列表</h3>
        <div class="search">
            <label>会员名称：</label>
            <input class="name" value="" id="uid" type="text" placeholder="请输入相应的信息" style="width: 150px"/>
            <label>选择日期：</label>
            <input type="text" class="layui-input" id="test1" value=""  placeholder="请输入相应的日期"
                   style="width: 150px">
            <button onclick="get_data(1)" class="s_button" style="background-color:  #3D89CB">搜索</button>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <thead>
            <tr>
                <th width="10%">UID</th>
                <th width="16%">openID</th>
                <th width="17%">微信昵称</th>
                <th width="10%">手机号码</th>
                <th>剩余次数</th>
                <th>绑定车牌数</th>
                <th>状态</th>
                <th width="10%">商户名</th>
                <th width="22%">操作</th>
            </tr>
            </thead>
            <tbody id="content" >
            </tbody>
        </table>
        <div id="page" class="ui-pagination-container">
        </div>
    </div>
</div>
</div>
<input type="hidden" value="1" id="p" >
</body>
</html>

<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1', //指定元素
        });
    });
    get_data(1);
    function get_data(p){
        var day = $('#test1').val();
        var uid = $('#uid').val();
        $.ajax({
            url:"/admin/user_list_post",
            type:"post",
            data:{
                'day':day,
                'uid':uid,
                'p':p
            },
            dataType:"json",
            success:function(msg){
                var q = '';
                if (msg.status == 1){
                      q += '<tr style="background-color: #0000001A">';
                    q += '<td >合计:' + msg.count+ '条</td>' ;
                    q += '<td ></td>' ;
                     q += '<td ></td>' ;
                    q += '<td ></td>' ;
                    q += '<td ></td>' ;
                    q += '<td ></td>' ;
                     q += '<td ></td>' ;
                     q += '<td ></td>' ;
                     q += '<td ></td>' ;
                            '</tr>';
                    for (var i = 0; i < msg.res.length; i++) {
                        q += '<tr>';
                        q += '<td>' + msg.res[i].uid + '</td>';
                        q += '<td>' + msg.res[i].wxOpenId + '</td>';
                        q += '<td>' + msg.res[i].wxNickName + '</td>';
                        q += '<td>' + msg.res[i].phone + '</td>';
                        q += '<td><a href="/admin/user/suit.html?uid=' + msg.res[i].uid + '" style="color: red"> '+ msg.res[i].wash_num + '</a></td>';
                        q += '<td><a onclick="content(' + msg.res[i].uid + ')">' + msg.res[i].user_cp + '</a></td>';
                        if (msg.res[i].status == 1) {
                            q += '<td>正常</td>';
                        } else {
                            q += '<td>已禁用</td>';
                        }
                        if (msg.res[i].bid != 0) {
                        q += '<td>' + msg.res[i].nickname + '</td>';
                        }else {
                             q += '<td></td>';
                        }
                        q += '<td>';
                        q += '<button class="blue"><a href="/admin/user_edit.html?uid=' + msg.res[i].uid + '">编辑</a></button>';
                        if (msg.res[i].status == 1){
                            q += ' <button class="ccc"><a onclick="stop(' + msg.res[i].uid + ')">禁用</a></button>';
                        }else {
                            q += ' <button class="green"><a onclick="member(' + msg.res[i].uid + ')">激活</a></button>';
                        }
                        q += ' <button class="red"><a onclick="de_user(' + msg.res[i].uid + ')">删除</a></button>';
                        if (msg.res[i].bid != 0) {
                        q += ' <button class="green"><a onclick="unbind(' + msg.res[i].uid + ')" > 解绑商户</a></button>';
                        }
                        q += ' <button class="layui-bg-orange"><a href="/admin/user_plate.html?uid=' + msg.res[i].uid + '">车牌管理</a></button>';
                        q += '</tr>';
                    }
                }else {
                    q  += '<tr><td colspan=8 align="center">无数据</td></tr>';
                }
                $('#content').html(q);
                $('#page').html(msg.page);
                $('#p').val(msg.p);
            }
        })
    }
    function stop(uid) {
        layer.open({
            content: '你确定禁用',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/stop_user_post',
                    type: 'post',
                    data: {
                        'uid': uid
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                get_data($('#p').val());
                            });
                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }

    function member(uid) {
        layer.open({
            content: '你确定激活',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/jh_user_post',
                    type: 'post',
                    data: {
                        'uid': uid
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                get_data($('#p').val());
                            });
                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }

    function unbind(uid) {
        layer.open({
            content: '你确定解绑',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/unbind',
                    type: 'post',
                    data: {
                        'uid': uid
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("解绑成功！", {time: 2000}, function () {
                                get_data($('#p').val());
                            });
                        } else {
                            layer.msg("解绑失败！");
                        }
                    }
                });
            }
        });
    }

    function de_user(uid) {
        layer.open({
            content: '你确定删除',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/delete_user_post',
                    type: 'post',
                    data: {
                        'uid': uid
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                get_data($('#p').val());
                            });
                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
    function content(uid){
        $.ajax({
            url:"/admin/user_plate",
            type:"post",
            data:{
                uid:uid
            },
            dataType:"json",
            success:function(msg){
                var q = '';
                if (msg.status == 1){
                    q += '<table width="95%" class="layui-table">';
                    q += '<tr><td width="90px">车牌号码</td><td width="120px">绑定时间</td></tr>';
                    for (var i = 0; i < msg.data.length; i++){
                        q += '<tr>';
                        q += '<td>' + msg.data[i].license_plate + '</td>';
                        q += '<td>' + msg.data[i].add_time + '</td>';
                        q += '</tr>';
                    }
                    q += '</table>';
                }else {
                    q += '<table class="layui-table"><tr><td colspan=8 align="center">用户没有绑定车牌</td></tr></table>';
                }
                layer.open({
                    type: 1,
                    title: '用户车牌',
                    closeBtn: false,
                    area: ['430px;', '280px'],
                    shade: 0.8,
                    id: 'LAY_layuipro', //设定一个id，防止重复弹出
                    btn: ['确定'],
                    btnAlign: 'c',
                    moveType: 1, //拖拽模式，0或者1
                    content: q,
                    success: function(layero){
                    }
                });

            }
        });

    }
</script>


